/**
 * user 模块
 */
import * as Mock from 'mockjs'
import { Succeed, Exception } from './index'
import { get_data } from './login json'
import { getRepository, getConnection } from 'typeorm'
import { User } from '../entity/User'

/** 个人信息 需要在 query 内传入 id */
export const get_user = async (req: any, res: any) => {
	// req.query.id , 查询个人信息需要的 id
	const { id } = req.query
	let tip: any = new Exception(400, '个人信息查找失败').toObject()
	if (id) {
		try {
			const SQL = getRepository(User)
			const user = await SQL.findOne(id)
			if (user) {
				tip = Succeed(user)
			}
		} catch (error) {
			tip = new Exception(400, error).toObject()
		}
	} else {
		tip = new Exception(400, '请传入id').toObject()
	}
	res.json(tip)
}

/** 关注的人 */
export const get_user_list = (req: any, res: any) => {
	res.json(
		Mock.mock(
			Succeed({
				// mock 格式需要 , 无法直接返回一个数组
				'list|15-50': [
					{
						'id|+1': 1,
						name: '@cname',
						age: '@integer(18, 23)',
						site: '@county(true)',
						img: `https://img.yzcdn.cn/vant/apple-${'@integer(1,8)'}.jpg`,
						text: '@csentence'
					}
				]
			})
		)
	)
}
